package com.sc.study.exam.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sc.common.annotation.Log;
import com.sc.common.core.controller.BaseController;
import com.sc.common.core.domain.AjaxResult;
import com.sc.common.enums.BusinessType;
import com.sc.study.exam.domain.ScQuestionOption;
import com.sc.study.exam.service.IScQuestionOptionService;
import com.sc.common.utils.poi.ExcelUtil;
import com.sc.common.core.page.TableDataInfo;

/**
 * 题目选项Controller
 * 
 * @author sc
 * @date 2022-02-27
 */
@RestController
@RequestMapping("/study/questionoption")
public class ScQuestionOptionController extends BaseController
{
    @Autowired
    private IScQuestionOptionService scQuestionOptionService;


    /**
     * 查询题目选项列表
     */
    @PreAuthorize("@ss.hasPermi('study:questionoption:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScQuestionOption scQuestionOption)
    {
        startPage();
        List<ScQuestionOption> list = scQuestionOptionService.selectScQuestionOptionList(scQuestionOption);
        return getDataTable(list);
    }

    /**
     * 导出题目选项列表
     */
    @PreAuthorize("@ss.hasPermi('study:questionoption:export')")
    @Log(title = "题目选项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScQuestionOption scQuestionOption)
    {
        List<ScQuestionOption> list = scQuestionOptionService.selectScQuestionOptionList(scQuestionOption);
        ExcelUtil<ScQuestionOption> util = new ExcelUtil<ScQuestionOption>(ScQuestionOption.class);
        util.exportExcel(response, list, "题目选项数据");
    }

    /**
     * 获取题目选项详细信息
     */
    @PreAuthorize("@ss.hasPermi('study:questionoption:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(scQuestionOptionService.selectScQuestionOptionById(id));
    }

    /**
     * 新增题目选项
     */
    @PreAuthorize("@ss.hasPermi('study:questionoption:add')")
    @Log(title = "题目选项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScQuestionOption scQuestionOption)
    {
        return toAjax(scQuestionOptionService.insertScQuestionOption(scQuestionOption));
    }

    /**
     * 修改题目选项
     */
    @PreAuthorize("@ss.hasPermi('study:questionoption:edit')")
    @Log(title = "题目选项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScQuestionOption scQuestionOption)
    {
        return toAjax(scQuestionOptionService.updateScQuestionOption(scQuestionOption));
    }

    /**
     * 删除题目选项
     */
    @PreAuthorize("@ss.hasPermi('study:questionoption:remove')")
    @Log(title = "题目选项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable("ids") Integer[] ids,@RequestBody(required = false) Integer[] questionIds){
        return toAjax(scQuestionOptionService.deleteScQuestionOptionByIds(ids, questionIds));
    }
}
